﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Could.Service;

namespace CatSentenceAnalyzer
{
    public class CatMakeData
    {
        private int[] m_Color = new int[5] { 0, 0x4240094, 0x979442, 0xc7c465, 0x999886 };
        public NPClass m_npclass;

        private TransData m_td1, m_td2;
        public TransData TdPrivate{
            set{
                m_td1 =  new TransData();
                m_td1.ArrList =(ArrayList)value.ArrList.Clone();
                m_td1.ElapsedTime = value.ElapsedTime;
                m_td1.TmsSearchLevel = value.TmsSearchLevel;
            }
        }
        public TransData TDMain{
            set{
                m_td2 = new TransData();
                m_td2.ArrList = (ArrayList)value.ArrList.Clone();
                m_td2.ElapsedTime = value.ElapsedTime;
                m_td2.TmsSearchLevel = value.TmsSearchLevel;
            }
        }

        private string TotalTime{
            get{
                string time1, time2;
                time1 = ((Convert.ToSingle(m_td1.ElapsedTime)) / 1000).ToString();
                //if (m_td2 != null)
               // time2 = ((Convert.ToSingle(m_td2.ElapsedTime)) / 1000).ToString();
                return time1;// +"/" + time2;
            }
        }
        public void MaketransTMSData()
        {
            ArrayList list;
            if (m_td2 == null){
                list = m_td1.ArrList;
            }else{
                list = m_td2.ArrList;
                if (m_td1.TmsSearchLevel > 0)
                {
                    list.InsertRange(1, m_td1.ArrList);
                }
            }
            TransData td = m_npclass.transdata;
            td.TmsTitle = ("匹配结果: 获得|1|条结果, 用时(|2|秒)");
            td.TmsTitle = td.TmsTitle.Replace("|1|", list.Count.ToString());
            td.TmsTitle = td.TmsTitle.Replace("|2|", TotalTime);
            string tmp = td.TmsResult = "";
            string sample = "<li><font size='13' color='#|3|'>|1|</font>\n<font size='13' color='#3399ff'>|2|</font></li>\n";
            for (int i = 0; i < list.Count; i++)
            {
                Tms tms = list[i] as Tms;
                tmp += sample.Replace("|1|", tms.oText);
                tmp = tmp.Replace("|2|", tms.tText);
                tmp = tmp.Replace("|3|", m_Color[td.TmsSearchLevel - CLangSegment.MININDEXTYPE].ToString());
            }
            td.TmsResult = tmp;
        }

        public void MaketransTDBData()
        {
            ArrayList list;
            if (m_td2 == null)
            {
                list = m_td1.ArrList;
            }else{
                list = m_td2.ArrList;
            }
            
            TransData td = m_npclass.transdata;
            td.TdbTitle = "术语，获得|1|条结果,用时(|2|秒)";//,匹配相关10个厂家";
            td.TdbTitle = td.TdbTitle.Replace("|1|", list.Count.ToString());
            td.TdbTitle = td.TdbTitle.Replace("|2|", TotalTime);
            //td.TdbResult = "<img src='http://localhost/catweb/assets/images/5.png'>" + "this's ：这是\n" + "解释：这是什么？\n" + "相关厂家:<a href='event:www.baidu.com' target='_blank'>百度<\a>";
            string tmp = "";
            string sample = "<li><font size='10' color='#000000'>|1|</font>\n<font size='10' color='#3399ff'>|2|</font></li>\n";
            for (int i = 0; i < list.Count; i++)
            {
                Tdb tdb = list[i] as Tdb;
                tmp += sample.Replace("|1|", tdb.oTerm);
                tmp = tmp.Replace("|2|", tdb.tTerm);
            }
            td.TdbResult = tmp;
        }
    }
}
